<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [1, 2, 3, 4, 4, 5, 5, 6, 6, 9, 8, 7];
        //1.数组去重
        let result = [...new Set(arr)];
        console.log(result);
        //2.交集
        let arr2 = [2, 4, 5, 9, 2, 8, 9];
        // let result = [...new Set(arr)].filter(item => {
        //     let s2 = new Set(arr2);
        //     //将s2去重
        //     //利用has方法检测arr中的在s2中是否也存在
        //     if (s2.has(item)) {
        //         return true;
        //     } else {
        //         return false;
        //     }
        // });
        // 简化写法
        // let result = [...new Set(arr)].filter(item =>
        //     new Set(arr2).has(item)
        // );
        // console.log(result);
        //3.并集
        // let union = [...new Set([...arr, ...arr2])];
        // console.log(union);
        //4.差集
        // let result = [...new Set(arr)].filter(item =>
        //     !(new Set(arr2).has(item))
        // );
        // console.log(result);
    </script>
</body>

</html>